package com.yingjie.addressbook;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class RecordActivity extends Activity {
	
	Button btnAll,btnDialed,btnReceived,btnMissed;
	String[] strNumbers;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.record);
        btnAll = (Button)findViewById(R.id.btnAll);
        btnDialed = (Button)findViewById(R.id.btnDialed);
        btnReceived = (Button)findViewById(R.id.btnReceived);
        btnMissed = (Button)findViewById(R.id.btnMissed);
        
        Intent intent = super.getIntent();
        Bundle bunde = intent.getExtras();  
        if(bunde != null){
        	strNumbers = bunde.getStringArray("Numbers"); 
        }else{
        	strNumbers = null;
        }
        BindRecord(strNumbers,-1);
        
        btnAll.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		BindRecord(strNumbers,-1);
        	}
        });
        btnReceived.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		BindRecord(strNumbers,1);
        	}
        });
        btnDialed.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		BindRecord(strNumbers,2);
        	}
        });
        btnMissed.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		BindRecord(strNumbers,3);
        	}
        });
	}
	
    public void BindRecord(String[] strNumbers,int iType){
    	ArrayList<HashMap<String,Object>> list = Record.getRecord(this,strNumbers,iType);
        SimpleAdapter  adapter = new SimpleAdapter (this,list,R.layout.record_list_row,new String[]{"Number","Name","Type","Time"} ,new int[]{R.id.itemNumeber,R.id.itemName,R.id.itemType,R.id.itemTime});
        ListView lv = (ListView)findViewById(R.id.lvRecord);
        lv.setAdapter(adapter);
    }
}
